using System;
using System.Collections.Generic;
using System.Text;

namespace ASMdll
{
	public class TranslationResult
	{
		private List<ProtocolRow> cmdList;
		private List<SymTabElement> symTab;
		private Byte[] code;
		Dictionary<int, string> errorReports;

		public TranslationResult()
		{
			cmdList = new List<ProtocolRow>();
			symTab = new List<SymTabElement>();
			errorReports = new Dictionary<int, string>();
		}

		public int ProtocolLength
		{
			get { return cmdList.Count; }
		}

		public int SymTabLength
		{
			get { return symTab.Count; }
		}

		public void AddProtocolRow(ProtocolRow nextRow)
		{
			cmdList.Add(nextRow);
		}

		public ProtocolRow GetProtocolRow(int ind)
		{
			return cmdList[ind];
		}

		public void AddSymTabElement(SymTabElement nextSymTabElement)
		{
			symTab.Add(nextSymTabElement);
		}

		public bool SymTabContains(string name, SymTabElement.SymType type)
		{
			for (int i = 0; i < symTab.Count; ++i)
				if (symTab[i].Name == name && symTab[i].Type == type)
					return true;
			return false;
		}

		public void SetLength(int length)
		{
			code = new Byte[length];
		}

		public Byte[] Code
		{
			get { return code; }
		}

		public UInt16 SymTabGetAddress(string name, SymTabElement.SymType type)
		{
			for (int i = 0; i < symTab.Count; ++i)
				if (symTab[i].Name == name && symTab[i].Type == type)
					return symTab[i].Address;
			throw new Exception("Internal compiler error!");
		}

		public Dictionary<int, string> ErrorReports
		{
			get { return errorReports; }
		}

		public List<SymTabElement> SymTab
		{
			get { return symTab; }
		}
	}

}
